jvc.window=new jvc_ui_window();
jvc.loadjs(jvc.baseUrl + "jvc/window.files/artDialog.js" );
jvc.loadjs(jvc.baseUrl + "jvc/window.files/iframeTools.js","artDialog.js" );

var jvc_ui_window_diag ;

var agt =   window.navigator.userAgent;
var isIE = agt.toLowerCase().indexOf("msie") != -1;
var isGecko = agt.toLowerCase().indexOf("gecko") != -1;
var ieVer = isIE ? parseInt(agt.split(";")[1].replace(/(^\s*)|(\s*$)/g,"").split(" ")[1]) : 0;
var isIE8 = !!window.XDomainRequest && !!document.documentMode;
var isIE7 = ieVer==7 && !isIE8;
var ielt7 = isIE && ieVer<7;

var $topWindow = function () {
    var parentWin = window;
   // while (parentWin != parentWin.parent) {
   //     if (parentWin.parent.document.getElementsByTagName("FRAMESET").length > 0) break;
   //     parentWin = parentWin.parent;
  //  }
    return parentWin;
};
var topWin = $topWindow();
var topDoc = topWin.document;
var getDom = function (id) {
    return typeof id == "string" ? document.getElementById(id) : id;
};
var bgDiv;
var getBgdiv = function () {
    if (bgDiv) return bgDiv;
    var bgdiv = topWin.getDom("_DialogBGDiv");
    if (!bgdiv) {
        bgdiv = topDoc.createElement("div");
        bgdiv.id = "_DialogBGDiv";
        bgdiv.style.cssText = "position:absolute;left:0px;top:0px;width:100%;height:100%;z-index:999999";
        var bgIframeBox = '<div style="position:relative;width:100%;height:100%;">';
		var bgIframeMask = '<div id="_DialogBGMask" style="position:absolute;background-color:#333;opacity:0.4;filter:alpha(opacity=40);width:100%;height:100%;"></div>';
		var bgIframe = ielt7?'<iframe src="about:blank" style="filter:alpha(opacity=0);" width="100%" height="100%"></iframe>':'';
		bgdiv.innerHTML=bgIframeBox+bgIframeMask+bgIframe+'</div>';
        topDoc.getElementsByTagName("BODY")[0].appendChild(bgdiv);
        if (ielt7) {
            var bgIframeDoc = bgdiv.getElementsByTagName("IFRAME")[0].contentWindow.document;
            bgIframeDoc.open();
            bgIframeDoc.write("<body style='background-color:#333' oncontextmenu='return false;'></body>");
            bgIframeDoc.close();
			bgIframeDoc=null;
        }
    }
    bgDiv = bgdiv;
	bgdiv=null;
    return bgDiv;
};
function jvc_ui_window_close(){	
		if(jvc_ui_window_diag){jvc_ui_window_diag.close();jvc_ui_window_diag=null;}
	}
	function jvc_ui_window(){
				this.close=function(){
				jvc_ui_window_close();
		}
	this.showHtml=function(text,height){
    var bgdiv = topWin.getDom("_DialogBGDivText");
    if (!bgdiv) {
        bgdiv = topDoc.createElement("div");
        bgdiv.id = "_DialogBGDivText";
        var iWidth = document.documentElement.clientWidth; 
 				var iHeight = document.documentElement.clientHeight;
 		if(!height)height=0;		
        bgdiv.style.cssText = "position:absolute;height:"+height+"px;left:"+(iWidth-200)/2+"px;top:"+(iHeight-height)/2+"px;z-index:9999;text-align:center;background:white";
    		topDoc.getElementsByTagName("BODY")[0].appendChild(bgdiv);
      }
		bgdiv.innerHTML=text;

		bgdiv.style.display="block";
				
	}
	this.showText=function(text){
			this.showHtml("<table><tr><td><img src='"+jvc.baseUrl+"../css/img/loading.gif'></td><td nowrap>"+text+"</td></tr></table>",40);
		}
	this.process=function(msg){
			var div=getBgdiv();
			div.style.display="block";
			 var topWinBody = topDoc.getElementsByTagName(topDoc.compatMode == "BackCompat" ? "BODY" : "HTML")[0];
	        topWinBody.styleOverflow = topWinBody.style.overflow;
    		if(window.navigator.userAgent.indexOf("Firefox/3.6") != -1){//在firefox下改变overflow属性会导致scrollTop=0;
    			var topWinBodyScrollTop=topWinBody.scrollTop;
		        topWinBody.style.overflow = "hidden";
    			topWinBody.scrollTop=topWinBodyScrollTop;
    		}else{
	        	topWinBody.style.overflow = "hidden";
	        }		
	       this.showText(msg);	
	}
	this.processEnd=function(){
		var textDiv = topWin.getDom("_DialogBGDivText");
		if(!textDiv)return;
		textDiv.style.display="none";
		var div=getBgdiv();
			div.style.display="none";
	        var topWinBody = topDoc.getElementsByTagName(topDoc.compatMode == "BackCompat" ? "BODY" : "HTML")[0];
	        if(topWinBody.styleOverflow != undefined)
	    		if(window.navigator.userAgent.indexOf("Firefox/3.6") != -1){//在firefox下改变overflow属性会导致scrollTop=0;
	    			var topWinBodyScrollTop=topWinBody.scrollTop;
			        topWinBody.style.overflow = topWinBody.styleOverflow;
	    			topWinBody.scrollTop=topWinBodyScrollTop;
	    		}else{
		        	topWinBody.style.overflow = topWinBody.styleOverflow;
		        }			
	}

this.alert = function (content,func,title) {
	(function (d) {
    d['okValue'] = '确定';
    d['cancelValue'] = '取消';
    d['title'] = '消息';
    // [more..]
})(art.dialog.defaults);

	if(!title)title="系统提示";
	return artDialog({
		id: 'Alert',
		title:title,
		icon: 'warning',
		fixed: true,
		lock: true,		
		content: content,
		ok: function(){
				if(func)func();				
				return true;
			}
	});
};



	this.confirm=function (sInfo,callback){		
		(function (d) {
		    d['okValue'] = '确定';
		    d['cancelValue'] = '取消';
		    d['title'] = '消息';
		})(art.dialog.defaults);
	
		art.dialog({
    content: sInfo,
    title:'信息确认',
    icon:'question',
    lock:true,
    ok: function () {
    	  if(callback)callback();
        return true;
    },
    cancelVal: '关闭',
    cancel: true //为true等价于function(){}
});


	}	
	
	this.showDiv=function(id,title){
			if(!title)title="系统提示";
	art.dialog({
    content: $$(id),
    title: title,
    lock: true,
    padding:'0px 0px'
});
		
	}
	
	this.prompt=function(content,value,yes){
		(function (d) {
    d['okValue'] = '确定';
    d['cancelValue'] = '取消';
    d['title'] = '消息';
    // [more..]
})(art.dialog.defaults);

		 value = value || '';
    var input;
    
    return artDialog({
        id: 'Prompt',
        icon: 'question',
        fixed: true,
        lock: true,
        opacity: .1,
        content: [
            '<div style="margin-bottom:5px;font-size:12px">',
                content,
            '</div>',
            '<div>',
                '<input value="',
                    value,
                '" style="width:18em;padding:6px 4px" />',
            '</div>'
            ].join(''),
        init: function () {
            input = this.DOM.content.find('input')[0];
            input.select();
            input.focus();
        },
        ok: function (here) {
            return yes && yes.call(this, input.value, here);
        },
        cancel: true
    });
	}
	this.openModal=function (sUrl,title,width,Height,callback){
			this.open(sUrl,title,width,Height,callback,true);
		
		}
	
	
this.tips = function (content, showType,time) {
	if(!showType)showType='success';
	this.showHtml("<table class='window_tips_box_"+showType+"'><tr><td width='2px' ></td><td class='window_tips_ico_"+showType+"'></td><td nowrap>"+content+"</td><td width='5px'></td></tr></table>");
  var that = this;
	setTimeout(function(){
         that.processEnd();
            }, time*1000 || 1.5*1000);
};

this.open2=function(j){
	if(!j.width)j.width=600;
	if(!j.height)j.height=300;
	if(!j.padding)j.padding=0;
	if(!this.frame_index)this.frame_index=0;
	this.frame_index++;
	var id="jvc_window_frame_open_"+this.frame_index;
	if(j.id) id="jvc_window_frame_open_"+j.id;
	if(j.url)j.content="<iframe id='"+id+"' src='"+j.url+"'  noresize='noresize'  border=0 frameborder=0 style='padding:0;margin:0;width:"+j.width+"px;height:"+j.height+"px;'></iframe>";
	jvc_ui_window_diag=art.dialog(j);
	if($$(id)){
		jvc_ui_window_diag.frame=$$(id).contentWindow;
	}else {
		if(window.frames[id].contentWindow){
			jvc_ui_window_diag.frame=window.frames[id].contentWindow;
		}else{
			jvc_ui_window_diag.frame=window.frames[id];
		}
	}
};

this.notice = function (options) {
    var opt = options || {},
        api, aConfig, hide, wrap, top,
        duration = 800;
        
    var config = {
        id: 'Notice',
        left: '100%',
        top: '100%',
        fixed: true,
        drag: false,
        resize: false,
        follow: null,
        lock: false,
        init: function(here){
            api = this;
            aConfig = api.config;
            wrap = api.DOM.wrap;
            top = parseInt(wrap[0].style.top);
            hide = top + wrap[0].offsetHeight;
            
            wrap.css('top', hide + 'px')
                .animate({top: top + 'px'}, duration, function () {
                    opt.init && opt.init.call(api, here);
                });
        },
        close: function(here){
            wrap.animate({top: hide + 'px'}, duration, function () {
                opt.close && opt.close.call(this, here);
                aConfig.close = $.noop;
                api.close();
            });
            
            return false;
        }
    };  
    
    for (var i in opt) {
        if (config[i] === undefined) config[i] = opt[i];
    };
    
    return artDialog(config);
};	

		
this.open = function (sUrl,title,width,height,callback,modal) {
	if(typeof sUrl != 'string') {this.open2(sUrl);return;}
	if(!width)width=600;
	if(!height)height=300;
	
	jvc_ui_window_diag=art.dialog({
    content: "<iframe src='"+sUrl+"'  noresize='noresize'  border=0 frameborder=0 style='padding:0;margin:0;width:"+width+"px;height:"+height+"px;'></iframe>",
    title: title,
    width:width,
    height:height,
	lock:modal,
    padding: 0,
    close:function(){
				if(callback)callback();
				return true;
			}
});
}

	
}
	
	